package com.budwk.app.sqfw.services.impl;

import com.budwk.app.sqfw.services.HuaweiOssService;
import org.nutz.ioc.impl.PropertiesProxy;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;

/**
 * @author ZY.Wang
 * @since 2023/6/26
 */
@IocBean
public class HuaweiOssServiceImpl implements HuaweiOssService {

    @Inject
    private PropertiesProxy propertiesProxy;

    public String getPwdPath(String relativePath) {
        String huaweiOssUrl = propertiesProxy.get("huawei-oss.url");

        String filePath = relativePath;
        if (filePath.contains(huaweiOssUrl)) filePath = filePath.replace(huaweiOssUrl, "");

        if (filePath.contains("AccessKeyId")) {
            filePath = filePath.substring(0, filePath.indexOf("AccessKeyId") - 1);
        }

        if (!filePath.startsWith("/")) filePath = "/" + filePath;
        return huaweiOssUrl + filePath;
    }
}
